//
//  AsAppDelegate.m
//  AsSDKDemo
//
//  Created by i4.cn\STM on 14-6-16.
//  Copyright (c) 2014年 i4.cn. All rights reserved.
//

#import "AsAppDelegate.h"

#import "AsInfoKit.h"
#include "AsPlatformSDK.h"

@implementation AsAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.asViewController = [[[AsViewController alloc] init] autorelease];
    self.window.rootViewController = self.asViewController;
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    ///************************************************************************************
    /*
     * SDK 新增了一个属性 AsInfoKit.h －－ orientationOfGame
     * SDK 新增了两种支付方式的回调：
     * 支付宝快捷支付的回调 asAlixPayResultCallBack
     * 银联支付的回调  asUPPayPluginResultCallBack
     */
    
    /*
     * 设置爱思平台的初始化参数
     * appId，appKey： 请从爱思后台获取，后台地址 http://dev.i4.cn ，登录账号是游戏方申请的开发者账号
     * logData： 设置为 YES 时，控制台会显示网络请求的数据；设置为 NO 时，控制台不会有网络请求的数据显示
     * closeRecharge： 设置为 YES 时，关闭充值功能；设置为 NO 时，打开充值功能
     * closeRechargeAlertMessage： 为关闭充值功能的提示语
     * longComet： 设置为 YES 时，为充值并兑换道具，爱思平台服务器会给游戏方服务器发送兑换道具成功或失败的消息；设置为 NO 时，为先打开爱思充值页面，给账户充值，将人民币兑换为爱思币。
     特别提醒：“- (void)asPayResultCallBack:(AsPayResultCode)paramPayResultCode”方法只会在账户的爱思币余额 >= 道具面额 时，才会执行，爱思币 < 道具面额 的情形下，该支付回调方法不会执行。
     爱思充值页面上所有的支付方式在支付完成或取消后，都会显示用户中心，可以在关闭用户中心的回调“- (void)asClosedCenterViewCallBack”中，判断用户的是否完成支付操作
     */
    [[AsInfoKit sharedInstance] setAppId:2];
    [[AsInfoKit sharedInstance] setAppKey:@"118255f8ffec4352a919c52d01a2d674"];
    [[AsInfoKit sharedInstance] setLogData:YES];
    [[AsInfoKit sharedInstance] setCloseRecharge:NO];
    [[AsInfoKit sharedInstance] setCloseRechargeAlertMessage:@"充值功能暂时不开放"];
    [[AsInfoKit sharedInstance] setLongComet:YES];
    /*
     * 参数(1) －－ 更新 SDK 使用环境
     * YES：使用的开发环境为 Xcode 6.x.x
     * NO： 使用的开发环境为 Xcode 5.x.x
     * --------------------------------------------------
     * 参数(2) －－ 获取游戏画面的方向
     * orientationOfGame 游戏画面的方向 :
     * UIInterfaceOrientationMaskPortrait : 正立
     * UIInterfaceOrientationMaskLandscapeLeft : 左横屏
     * UIInterfaceOrientationMaskLandscapeRight : 右横屏
     * UIInterfaceOrientationMaskLandscape : 横屏（可上下翻转）
     * UIInterfaceOrientationMaskAll : 所有方向
     */
    // 接入sdk时，根据使用的Xcode版本 与 游戏画面的方向更改此处，使用Xcode 6.x.x设置为YES，使用Xcode 5.x.x 设置为NO；游戏画面方向为 横屏 ，设置为 UIInterfaceOrientationMaskLandscape；竖屏，设置为UIInterfaceOrientationMaskPortrait
    [[AsInfoKit sharedInstance] updateSDKOperatingEnvironment:YES andOrientationOfGame:UIInterfaceOrientationMaskLandscape];
    /*
     * 检查游戏是否有更新的接口（默认是非强制更新，如需要强制更新，请联系爱思商务）
     * 检查更新接口的回调是：asVerifyingUpdatePassCallBack
     */
    [[AsPlatformSDK sharedInstance] checkGameUpdate];
    ///************************************************************************************

    
    return YES;
}

- (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    
    if ([sourceApplication isEqualToString:@"com.alipay.iphoneclient"])
    {
        [[AsInfoKit sharedInstance] alixPayResult:url];
    }
    else if ([sourceApplication isEqualToString:@"com.alipay.safepayclient"])
    {
        [[AsInfoKit sharedInstance] alixPayResult:url];
    }
    else if ([sourceApplication isEqualToString:@"com.tencent.xin"])
    {
        [[AsInfoKit sharedInstance] weChatPayResult:url];
    }
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)dealloc
{
    [_window release];
    [_asViewController release];
    [super dealloc];
}

@end
